package com.woniuxy.main.utils;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.dsna.util.images.ValidateCode;

@Controller
@RequestMapping("/picCode")
public class PictureCodeHandler {
	@RequestMapping("/getCode")
	@ResponseBody
	public void getCode(HttpServletRequest request,HttpServletResponse response){
		ValidateCode code=new ValidateCode(110, 40, 1, 20);
		//获取验证码
		String codeVal=code.getCode();
		//将验证码存到session
		request.getSession().setAttribute("loginCode", codeVal);
		//将图形化验证码响应到客户端
		try {
			code.write(response.getOutputStream());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
